class Singer < ApplicationRecord
  scope :ordered, -> { order(is_shown: :desc, id: :asc) }

  belongs_to :singer_tag
  has_and_belongs_to_many :songs
  has_and_belongs_to_many :singer_favs

  class << self
    def init_and_max_pages
      max_count = group(:singer_tag_id).count
      max_pages = max_count.inject({}) { |h, (k, v)| h[k] = (v / 16.0).ceil; h }
      init_pages = max_count.inject({}) { |h, (k, v)| h[k] = 1; h }
      [max_pages, init_pages]
    end
  end
end
